package com.teafriend.controller;

import com.teafriend.entity.Teafriend;
import com.teafriend.service.TeafriendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 茶友控制器
 * @author 欧楚杨
 */
@RestController
@RequestMapping("/chuyangc/teafriend/")
@Api(tags = "茶友相关的请求")
public class TeafriendController {
    @Autowired
    TeafriendService teafriendService;

    @GetMapping("/listtf")
    @ApiOperation("查询所有茶友")
    @ApiImplicitParam()
    public List<Teafriend> listTeafriend(){
        return teafriendService.list();
    }

    @DeleteMapping("/deltf/{id}")
    @ApiOperation("根据茶友id删除数据")
    @ApiImplicitParam(name = "茶友id",value = "id",required = true)
    public boolean delTeafriend(@PathVariable("id") Integer id){
        return teafriendService.removeById(id);
    }

    @PostMapping("/addtf")
    @ApiOperation("添加茶友")
    @ApiImplicitParam(name = "茶友实体类对象",value = "teafriend",required = true)
    public boolean addTeafriend(@RequestBody Teafriend teafriend) {
        return teafriendService.save(teafriend);
    }

    @GetMapping("/searchtf/{id}")
    @ApiOperation("根据id查找茶友")
    @ApiImplicitParam(name = "茶友id",value = "id",required = true)
    public Teafriend searchTeafriend(@PathVariable Integer id){
        return teafriendService.getById(id);
    }

    @PostMapping("/updatetf")
    @ApiOperation("根据茶友id修改信息")
    @ApiImplicitParam(name = "茶友实体类对象",value = "teafriend",required = true)
    public boolean updateTeafriend(@RequestBody Teafriend teafriend) {
        return teafriendService.updateById(teafriend);
    }
}
